var maxSubArray = function(nums) {
    if(nums.length === 1) return nums[0]
    let slow = 0
    let quick = 0
    let sum = nums[0]
    let nowSum = sum
    while(quick < nums.length){
        if(nowSum >= sum) {
            sum = nowSum
            quick++
            nowSum = nums.slice(slow,quick).reduce((a,b)=>a+b,0)
        } else {
            while(slow !== quick || nowSum < sum){
                slow++
                nowSum = nums.slice(slow,quick).reduce((a,b)=>a+b,0)
            }
        }
    }
    return sum
};
console.log(maxSubArray([-2,1,-3,4,-1,2,1,-5,4]));